package com.cjzuji.rental.Bean;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.pojo.Orders;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.LinkedHashMap;
import java.util.Map;

@Data
public class OrderData {
    /**
     * 存储A行数据（订单基本信息）
     */
    private Map<String, String> basicInfo = new LinkedHashMap<>();

    /**
     * 存储B行数据（商品信息）
     */
    private Map<String, String> productInfo = new LinkedHashMap<>();

    /**
     * 存储C行数据（用户信息）
     */
    private Map<String, String> userInfo = new LinkedHashMap<>();

    @Autowired
    OrderMapper OrderMapper;

    /**
     * 获取合并后的所有数据
     */
    public Map<String, String> getAllData() {
        Map<String, String> allData = new LinkedHashMap<>();
        allData.putAll(basicInfo);
        allData.putAll(productInfo);
        allData.putAll(userInfo);
        return allData;
    }
    public ApiResponse getLateData(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize) {
        try {
            Page page = new Page(pageIndex,pageSize);
            QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
            Page<Orders> pageResult = OrderMapper.selectPage(page, queryWrapper);
            return ApiResponse.success(pageResult);
        }
        catch(Exception e){
            return ApiResponse.error("588","服务器内部错误:"+e.getMessage());
        }
    }
}